/* jshint esversion: 6 */
import Vue from 'vue';
import Router from 'vue-router';
import {config} from '../../static/config'
import store from '../store';
window.store = store;

Vue.use(Router);

const router = new Router({
    // mode: "history",
    routes: [
        {
            path: '/',
            component: () => import('@/pages/index/index.vue'), //index页面
            meta: {
                title: config.common.title
            },
        },
        {
            path: '/mobileIndex',
            component: () => import('@/pages/index/mobileIndex.vue'), //mobileIndex页面
            meta: {
                title: config.common.title
            },
        },
        {
            path: '/login',
            name: 'login',
            meta: {
                title: '登录'
            },
            component: () => import('@/pages/login/login.vue')  //登录页面
        },
        {
            path: '/share',
            meta: {
                title: 'DLHTX导航分享'
            },
            component: () => import('@/pages/share/share.vue')  //DLHTX导航分享
        }
    ]
})

router.beforeEach((to, from, next) => {
    if (to.matched.some(record => record.meta.requiresAuth)) {
        // store.dispatch('checkLogin').then(isLogin => {
        //     if (!isLogin) {
        //         console.log(to.fullPath)
        //         next({
        //             path: '/login',
        //             query: { redirect: to.fullPath }
        //         })
        //     } else {
        //         next()
        //     }
        // })
    }
    else {
        next() // 确保一定要调用 next()
    }

    if (to.matched.some(record => record.meta.title)) {
        console.log(to.meta.title)
        document.title = to.meta.title
    } else {
        next() // 确保一定要调用 next()
    }
})

export default router

